import {
  Controller,
  Get,
  HttpCode,
  Param,
  Query,
  Req,
  Post,
  Body,
  UsePipes,
  UseFilters,
  UseGuards,
  SetMetadata,
} from '@nestjs/common';
import { UserService } from './user.service';
import { Request } from 'express';
import {
  ApiBody,
  ApiOperation,
  ApiParam,
  ApiQuery,
  ApiTags,
} from '@nestjs/swagger';
import { UserFilter } from 'src/filter/user.filter';
import { IsNotEmptyPipe } from 'src/pipes/is-not-empty.pipe';
import { UserInfo } from 'src/Dto/User.Dto';
// import { UserInfo } from '../../Dto/User.Dto'; //注册前端提交数据类型
// import { IsNotEmptyPipe } from '../../pipes/is-not-empty.pipe'; //验证不为空管道
// import { UserFilter } from '../../filter/user.filter';
@Controller('user')
@ApiTags('Nest')
export class UserController {
  constructor(private user: UserService) { }
  @Get('')
  @HttpCode(200)
  getUsers(@Req() req: Request) {
    return this.user.getUsers();
  }

  @Get('query')
  @ApiQuery({ name: 'a' })
  @ApiQuery({ name: 'b' })
  @ApiQuery({ name: 'c', required: false })
  @HttpCode(200)
  getUserByQuery(@Query() query) {
    return query;
  }

  @Get(':id')
  @ApiParam({ name: 'id' })
  @HttpCode(200)
  getUserById(@Param() params) {
    return params;
  }

  @Post()
  @HttpCode(200)
  @UseFilters(new UserFilter())
  @ApiOperation({ summary: '用户注册' })
  register(@Body(IsNotEmptyPipe) userInfo: UserInfo) {
    return userInfo;
  }
}
